import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/user_controller.dart';

import '../../../widget/avatarPopupMenu.dart';
import '../../../services/screenAdapter.dart';

class UserView extends GetView<UserController> {
  const UserView({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("Flutter Api", style: TextStyle(color: Colors.white)),
        backgroundColor: Colors.black,
        automaticallyImplyLeading: false, //
        // centerTitle: true,
        actions: [AvatarPopupMenu()],
      ),
      body: Center(
        child: Container(
          width: Get.width * 0.5,
          padding: EdgeInsets.fromLTRB(
            ScreenAdapter.width(200),
            ScreenAdapter.height(100),
            ScreenAdapter.width(200),
            0,
          ),
          child: Column(
            children: [
              SizedBox(
                width: ScreenAdapter.width(100),
                height: ScreenAdapter.height(100),
                child: GestureDetector(
                  onTap: controller.pickImage,
                  child: Obx(() {
                    return CircleAvatar(
                      radius: 80,
                      backgroundImage: NetworkImage(
                        controller.avatarUrl.value,
                      ),
                    );
                  }),
                ),
              ),
              SizedBox(height: ScreenAdapter.height(24)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '用户名称：',
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(16),
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  Expanded(
                    child: TextFormField(
                      controller: controller.editUserNameController,
                      decoration: InputDecoration(
                        hintText: "请输入用户名称",

                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(8),
                          borderSide: BorderSide(color: Colors.grey[300]!),
                        ),
                      ),
                    ),
                  ),
                ],
              ),

              SizedBox(height: ScreenAdapter.height(24)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '手机号码：',
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(16),
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  Expanded(
                    child: TextFormField(
                      controller: controller.editPhoneController,
                      decoration: InputDecoration(
                        hintText: "请输入用户手机号 ",

                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(8),
                          borderSide: BorderSide(color: Colors.grey[300]!),
                        ),
                      ),
                    ),
                  ),
                ],
              ),

              SizedBox(height: ScreenAdapter.height(24)),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    '登录密码：',
                    style: TextStyle(
                      fontSize: ScreenAdapter.fontSize(16),
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                  Expanded(
                    child: TextFormField(
                      obscureText: true,
                      controller: controller.editPasswordController,
                      decoration: InputDecoration(
                        hintText: "请输入登录密码 ",
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(8),
                          borderSide: BorderSide(color: Colors.grey[300]!),
                        ),
                      ),
                    ),
                  ),
                ],
              ),

              SizedBox(height: ScreenAdapter.height(24)),

              // 操作按钮
              ElevatedButton(
                onPressed: () {
                  controller.submitEditUserForm();
                },
                style: ElevatedButton.styleFrom(
                  padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
                ),
                child: SizedBox(
                  width: ScreenAdapter.width(300),
                  height: ScreenAdapter.height(50),
                  child: const Center(child: Text('确认')),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
